package com.cjst.service.impl.part;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cjst.dao.mapper.part.PtypeRelevanceMapper;
import com.cjst.pojo.part.PtypeRelevance;
import com.cjst.service.impl.base.BaseServiceImpl;
import com.cjst.service.part.PtypeRelevanceService;
import com.cjst.sql.C;
import com.cjst.sql.Method;
import com.cjst.sql.WherePrams;


@Service
public class PtypeRelevanceServiceImpl extends  BaseServiceImpl<PtypeRelevance, String> implements PtypeRelevanceService {
	@Autowired 
	private PtypeRelevanceService ptypeRelevance;

	@Autowired
	private PtypeRelevanceMapper ptypeRelevanceMapper;

	@Override
	@Transactional
	public void setRelevance(String partsId, String ids) {
		// TODO Auto-generated method stub
				//删除改角色拥有的权限
				WherePrams wherePrams = Method.where("partId", C.EQ, partsId);
				ptypeRelevance.del(wherePrams);
				//为该角色新增权限
				if(StringUtils.isNotEmpty(ids)){
					String[] arr = ids.split(",");
					for (String id : arr) {
						PtypeRelevance ptypeRelevance = new PtypeRelevance();
						ptypeRelevance.setPartId(partsId);
						ptypeRelevance.setTypeId(id);
						this.addLocalByid(ptypeRelevance);
						
					}
				}
				//redisService.setObj(CommonConstant.SESSION_ROLE_AUTH, null);
				
		
	}

	@Override
	public List<Map<String, Object>> getRelevanceIds(String partsId) {
		// TODO Auto-generated method stub
		List<Map<String, Object>> maps = ptypeRelevanceMapper.getRelevanceIds(partsId);
		return maps;
	}

}
